<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子13-ES6/7常用语法介绍</title>
    </head>
    <body>
        <pre>
            <code>
                // 例子13

                // (1) 交换变量的值
                let x = 1;
                let y = 2;
                [x, y] = [y, x];

                //--------------------------------------------------------------------------

                // (2) 从函数返回多个值
                // 返回一个数组
                function example1() {
                    return [1, 2, 3];
                }
                let [a, b, c] = example1();

                // 返回一个对象
                function example2() {
                    return {
                        foo: 1,
                        bar: 2
                    };
                }
                let { foo, bar } = example2();

                //--------------------------------------------------------------------------

                // (3) 函数参数的定义和默认值
                // 参数是一组有次序的值
                function f1([x, y, z]) {
                   // ...
                }
                f1([1, 2, 3]);

                // 参数是一组无次序的值
                function f2({x, y, z}) {
                    //...
                }
                f2({z: 3, y: 2, x: 1});

                // 函数参数默认值
                jQuery.ajax = function (url, {
                    async = true,
                    beforeSend = function () {},
                    cache = true,
                    complete = function () {},
                    crossDomain = false,
                    global = true,
                    // ... more config
                } = {}) {
                    // ... do stuff
                };

                //--------------------------------------------------------------------------

                // (4) 提取JSON数据
                let jsonData = {
                    id: 42,
                    status: "OK",
                    data: [867, 5309]
                };

                let { id, status, data: number } = jsonData;
                console.log(id, status, number);	// 42 "OK" [867, 5309]

                //--------------------------------------------------------------------------

                (5) 引入模块的指定方法
                const { SourceMapConsumer, SourceNode } = require("source-map");
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/13.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>